home *** CD-ROM | disk | FTP | other *** search
- /******** System includes ********/
- #include <Quickdraw.h>
- #include <ControlMgr.h>
- #include <MemoryMgr.h>
- #include <OSUtil.h>
- #include <FontMgr.h>
- #include <SetupA4.h>
- /**********************************/
-
- /******** defines ********/
- #define NULL 0L
- #define CONTROL_WINDOW ( (*my_control)->contrlOwner )
- #define CONTROL_VISIBLE ( (*my_control)->contrlVis )
- #define CONTROL_HILITE ( (*my_control)->contrlHilite )
- #define CONTROL_VALUE ( (*my_control)->contrlValue )
- #define CONTROL_MIN ( (*my_control)->contrlMin )
- #define CONTROL_MAX ( (*my_control)->contrlMax )
- #define CONTROL_TITLE ( (*my_control)->contrlTitle )
- #define CONTROL_RECT (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).control_rect
- #define CONTROL_RECT_LEFT (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).control_rect.left
- #define CONTROL_RECT_TOP (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).control_rect.top
- #define CONTROL_RECT_RIGHT (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).control_rect.right
- #define CONTROL_RECT_BOTTOM (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).control_rect.bottom
- #define CONTROL_DATE_TIME (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).date_time
- #define CONTROL_FONT_WIDTH (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).font_width
- #define CONTROL_FONT_HEIGHT (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).font_height
- #define CONTROL_ITEM_RECT (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).item_rect
- #define CONTROL_ITEM_HILITE (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).item_hilite
- #define CONTROL_ITEM_UPDATE (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).item_update
- #define CONTROL_CHAR_POS (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).char_point
- #define CONTROL_CHAR_ARY (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).character
- #define CONTROL_HILITED (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).item_hilited
- #define CONTROL_LST_HILITED (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).last_hilite
- #define NEW_CLIP (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).new_clip
- #define OLD_CLIP (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).old_clip
- #define DE_BOUNCER (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).de_bouncer
- #define NUM_DAYS (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).num_days
- #define NEW_DATE_TIME (**(DATE_TIME_CONTROL_HDL)\
- ((*my_control)->contrlData)).new_date_time_rec
- #define MONTH_PART_CODE 1
- #define DAY_PART_CODE 2
- #define YEAR_PART_CODE 3
- #define HOUR_PART_CODE 4
- #define MINUTE_PART_CODE 5
- #define UP_ARROW 6
- #define DOWN_ARROW 7
- #define CHARACTER_OFFSET 0
- #define DATE_TIME_OFFSET 8
- #define TOP_DOWN_MARGIN 4
- #define NUM_CHARS 13
- #define NUM_PARTS 8
- #define CONTROL_FONT systemFont
- #define CONTROL_FONT_SIZE 0
- #define CONTROL_FONT_STYLE 0
- #define DELAY 7
- /**********************************/
-
-
- /******** Global variables ********/
- /* These guys must be put in a structure */
- typedef struct {
- DateTimeRec date_time ; /* current time as set by the control */
- Rect item_rect[NUM_PARTS] ; /* item rect array */
- int font_width ; /* font width */
- int font_height ; /* font height */
- int item_hilite[NUM_PARTS] ; /* item hilite array */
- int item_update[NUM_PARTS] ; /* item update array */
- Point char_point[NUM_CHARS] ; /* pen position array for each character */
- int character[NUM_CHARS] ; /* character array */
- int item_hilited ; /* current item hilited */
- int last_hilite ; /* last item hilited */
- RgnHandle old_clip ; /* scratch rgnhandle */
- RgnHandle new_clip ; /* scratch rgnhandle */
- Rect control_rect ; /* control rect */
- int de_bouncer ; /* up/down arrow click delay */
- int num_days[12] ; /* days in month array */
- DateTimeRec new_date_time_rec ; /* date time rect provide for application */
- } DATE_TIME_CONTROL, *DATE_TIME_CONTROL_PTR, **DATE_TIME_CONTROL_HDL ;
- /**********************************/
-
- /******** Subroutine prototypes ********/
- pascal long main( int, ControlHandle, int, long ) ;
- void doDrawControl( long, ControlHandle ) ;
- long doTestControl( long, ControlHandle ) ;
- void doCalcCRgns( RgnHandle, ControlHandle ) ;
- void doInitControl( ControlHandle ) ;
- void doTrackControl( int, ControlHandle ) ;
- void Date2Chars( DateTimeRec *, int * ) ;
- /****************************************/
-
- /******** Bitmap for arrows ***************/
- char bits[2*18] = {
- 0x3F, 0x80,
- 0x40, 0x40,
- 0x84, 0x20,
- 0x8E, 0x20,
- 0x9F, 0x20,
- 0xBF, 0xA0,
- 0x8E, 0x20,
- 0x8E, 0x20,
- 0x80, 0x20,
- 0x80, 0x20,
- 0x8E, 0x20,
- 0x8E, 0x20,
- 0xBF, 0xA0,
- 0x9F, 0x20,
- 0x8E, 0x20,
- 0x84, 0x20,
- 0x40, 0x40,
- 0x3F, 0x80 } ;
- /****************************************/
-
- /******** CDEF 2 call with proc id 16*2 32 ********/
- pascal long main( varCode, my_control, message, param )
- int varCode ;
- ControlHandle my_control ;
- int message ;
- long param ;
- {
- GrafPtr old_port ;
- PenState pen_state ;
- int i ;
- Point p ;
- long result ;
-
- /* Set up a4 */
- RememberA0( ) ;
- SetUpA4( ) ;
-
- /* Initialize function result */
- result = 0 ;
-
- /* Initial setup */
- if( ( (**my_control).contrlData == NULL ) && ( message != initCntl ) ) {
- return result ;
- }else if( (**my_control).contrlData != NULL ) {
- HLock( (**my_control).contrlData ) ;
- }
- HLock( my_control ) ;
-
- /* Save port information */
- GetPort( &old_port ) ;
- SetPort( CONTROL_WINDOW ) ;
- GetPenState( &pen_state ) ;
- PenNormal( ) ;
-
- /* Set the font */
- TextFont( CONTROL_FONT ) ;
- TextFace( CONTROL_FONT_STYLE ) ;
- TextSize( CONTROL_FONT_SIZE ) ;
-
- /* Check for control being repositioned, or date being set manually by program */
- if( message != initCntl ) {
- /* If rects do not match */
- if( ( (*my_control)->contrlRect.top != CONTROL_RECT_TOP ) ||
- ( (*my_control)->contrlRect.left != CONTROL_RECT_LEFT ) ) {
- /* Update item rects */
- for( i = 0; i<NUM_PARTS;i++ ) {
- OffsetRect( &CONTROL_ITEM_RECT[i],
- (*my_control)->contrlRect.left - CONTROL_RECT_LEFT,
- (*my_control)->contrlRect.top - CONTROL_RECT_TOP ) ;
- }
- /* Now update character rects */
- p.h = (*my_control)->contrlRect.left - CONTROL_RECT_LEFT ;
- p.v = (*my_control)->contrlRect.top - CONTROL_RECT_TOP ;
- for( i = 0; i<NUM_CHARS;i++ ) {
- AddPt( p, &CONTROL_CHAR_POS[i] ) ;
- }
- OffsetRect( &CONTROL_RECT,
- (*my_control)->contrlRect.left - CONTROL_RECT_LEFT,
- (*my_control)->contrlRect.top - CONTROL_RECT_TOP ) ;
- }
- /* Now check to see if time has changed */
- if( ( NEW_DATE_TIME.year != CONTROL_DATE_TIME.year ) ||
- ( NEW_DATE_TIME.month != CONTROL_DATE_TIME.month ) ||
- ( NEW_DATE_TIME.day != CONTROL_DATE_TIME.day ) ||
- ( NEW_DATE_TIME.hour != CONTROL_DATE_TIME.hour ) ||
- ( NEW_DATE_TIME.minute != CONTROL_DATE_TIME.minute ) ) {
- CONTROL_DATE_TIME = NEW_DATE_TIME ;
- Date2Chars( &CONTROL_DATE_TIME, CONTROL_CHAR_ARY ) ;
- doDrawControl( 0, my_control ) ;
- }
- }
-
- /* Now handle control messages */
- switch( message ) {
- case initCntl: /* Initialize control */
- doInitControl( my_control ) ;
- break ;
- case drawCntl: /* draw the control */
- if( CONTROL_VISIBLE ) {
- doDrawControl( param, my_control) ;
- }
- break ;
- case testCntl: /* test where mouse button was pressed */
- result = doTestControl( param, my_control ) ;
- break ;
- case calcCRgns: /* calculate controls region */
- param = param & 0x00FFFFFF ; /* Mask out hi byte */
- doCalcCRgns( (RgnHandle)param, my_control ) ;
- break ;
- case autoTrack: /* track mouse hits */
- doTrackControl( param, my_control ) ;
- break ;
- case dispCntl: /* dispose data storage for control */
- DisposeRgn( OLD_CLIP ) ;
- DisposeRgn( NEW_CLIP ) ;
- DisposHandle( (**my_control).contrlData ) ;
- break ;
- case posCntl: /* Handled by default */
- case dragCntl:
- break ;
- }
-
- /* Restore grafport */
- SetPenState( &pen_state ) ;
- SetPort( old_port ) ;
-
- /* Unlock handle to data to minimize heap fragmentation */
- if( (**my_control).contrlData != NULL ) {
- HUnlock( (**my_control).contrlData ) ;
- }
-
- /* Restore a4 */
- RestoreA4( ) ;
-
- return result ;
- }
- void doInitControl( my_control )
- ControlHandle my_control ;
- {
- FontInfo font_info ;
- Rect box ;
- int i ;
- char **hdl ;
-
- /* Allocate and lock data storage */
- (**my_control).contrlData = NewHandle( sizeof( DATE_TIME_CONTROL ) ) ;
- if( (**my_control).contrlData == NULL ) {
- return ;
- }
- HLock( (**my_control).contrlData ) ;
-
- /* Set up controls rect and init data area */
- SetRect( &CONTROL_RECT, 0, 0, 140, 24 ) ;
- OffsetRect( &CONTROL_RECT, (*my_control)->contrlRect.left,
- (*my_control)->contrlRect.top ) ;
- (*my_control)->contrlAction = (ProcPtr)-1 ;
- OLD_CLIP = NewRgn( ) ;
- NEW_CLIP = NewRgn( ) ;
-
- /* Initialize time structure */
- GetTime( &CONTROL_DATE_TIME ) ;
- Date2Chars( &CONTROL_DATE_TIME, CONTROL_CHAR_ARY ) ;
- NEW_DATE_TIME = CONTROL_DATE_TIME ;
-
- /* Now init character rects */
- /* Get the font information */
- GetFontInfo( &font_info ) ;
-
- /* Get height and width */
- CONTROL_FONT_WIDTH = font_info.widMax - 6 ;
- CONTROL_FONT_HEIGHT = font_info.ascent ;
-
- /* Calculate item rects now */
- box = CONTROL_RECT ;
- box.top = box.top + TOP_DOWN_MARGIN ;
- box.bottom = box.top + CONTROL_FONT_HEIGHT ;
- box.left = CONTROL_RECT_LEFT + DATE_TIME_OFFSET ;
- box.right = box.left + 2*CONTROL_FONT_WIDTH + CHARACTER_OFFSET ;
- /* Init char points */
- for( i=0;i<NUM_CHARS;i++){
- CONTROL_CHAR_POS[i].v = box.bottom ;
- }
- box.bottom += 2 ;
-
- i = 0 ;
- /* Calculate total rect */
- CONTROL_ITEM_RECT[0] = CONTROL_RECT ;
-
- /* Calculate month rect and character points */
- CONTROL_ITEM_RECT[MONTH_PART_CODE] = box ;
- CONTROL_CHAR_POS[i++].h = box.left ;
- CONTROL_CHAR_POS[i++].h = box.left + CHARACTER_OFFSET + CONTROL_FONT_WIDTH ;
-
- /* Now calc position for first slash */
- CONTROL_CHAR_POS[i++].h = box.right + CHARACTER_OFFSET ;
-
- /* Calculate day rect and character points */
- OffsetRect( &box, ( CONTROL_FONT_WIDTH + 2*CHARACTER_OFFSET +
- ( box.right - box.left ) ),0 ) ;
- CONTROL_ITEM_RECT[DAY_PART_CODE] = box ;
- CONTROL_CHAR_POS[i++].h = box.left ;
- CONTROL_CHAR_POS[i++].h = box.left + CHARACTER_OFFSET + CONTROL_FONT_WIDTH ;
-
- /* Now calc position for second slash */
- CONTROL_CHAR_POS[i++].h = box.right + CHARACTER_OFFSET ;
-
- /* Calculate year rect and character points */
- OffsetRect( &box, ( CONTROL_FONT_WIDTH + 2*CHARACTER_OFFSET +
- ( box.right - box.left ) ),0 ) ;
- CONTROL_ITEM_RECT[YEAR_PART_CODE] = box ;
- CONTROL_CHAR_POS[i++].h = box.left ;
- CONTROL_CHAR_POS[i++].h = box.left + CHARACTER_OFFSET + CONTROL_FONT_WIDTH ;
-
- /* Calculate hour rect and character points */
- OffsetRect( &box, ( DATE_TIME_OFFSET + ( box.right - box.left ) ),0 ) ;
- CONTROL_ITEM_RECT[HOUR_PART_CODE] = box ;
- CONTROL_CHAR_POS[i++].h = box.left ;
- CONTROL_CHAR_POS[i++].h = box.left + CHARACTER_OFFSET + CONTROL_FONT_WIDTH ;
-
- /* Now calc position for colon */
- CONTROL_CHAR_POS[i++].h = box.right + CHARACTER_OFFSET ;
-
- /* Calculate minute rect and character points */
- OffsetRect( &box, ( CONTROL_FONT_WIDTH - 4 + 2*CHARACTER_OFFSET +
- ( box.right - box.left ) ),0 ) ;
- CONTROL_ITEM_RECT[MINUTE_PART_CODE] = box ;
- CONTROL_CHAR_POS[i++].h = box.left ;
- CONTROL_CHAR_POS[i++].h = box.left + CHARACTER_OFFSET + CONTROL_FONT_WIDTH ;
-
- /* Calculate up and down buttons rects */
- OffsetRect( &box, ( DATE_TIME_OFFSET + ( box.right - box.left ) ),0 ) ;
- box.top -= 2 ;
- box.right = box.left + 11 ;
- box.bottom = box.top + 9 ;
- CONTROL_ITEM_RECT[UP_ARROW] = box ;
- OffsetRect( &box, 0, 9 ) ;
- CONTROL_ITEM_RECT[DOWN_ARROW] = box ;
-
- /* Zero all the update and hilite arrays out */
- for( i=0;i<NUM_PARTS;i++) {
- CONTROL_ITEM_UPDATE[i] = TRUE ;
- CONTROL_ITEM_HILITE[i] = FALSE ;
- }
-
- /* Init control hilites */
- CONTROL_HILITED = 0 ;
- CONTROL_LST_HILITED = 0 ;
-
- /* This is the number of times autoTrack must be called before updating date */
- DE_BOUNCER = DELAY ;
-
- /* Number of days in the month */
- NUM_DAYS[0] = 31 ;
- NUM_DAYS[1] = 28 ;
- NUM_DAYS[2] = 31 ;
- NUM_DAYS[3] = 30 ;
- NUM_DAYS[4] = 31 ;
- NUM_DAYS[5] = 30 ;
- NUM_DAYS[6] = 31 ;
- NUM_DAYS[7] = 31 ;
- NUM_DAYS[8] = 30 ;
- NUM_DAYS[9] = 31 ;
- NUM_DAYS[10] = 30 ;
- NUM_DAYS[11] = 31 ;
-
- /* Handle leap years */
- /* Note: year MOD 4 handles the leap year every 4 years but this does not take into
- account the fact that every 4 centuries the leap year is skipped. This will
- happen again in the year 2000, which by our algorithm is a leap year, but in
- acuality is not. If this code is still in use till the year 2000 I will gladly
- update it. */
- if( ( CONTROL_DATE_TIME.year % 4 ) == 0 ) {
- NUM_DAYS[1] = 29 ;
- }else{
- NUM_DAYS[1] = 28 ;
- }
-
- return ;
- }
- void doDrawControl( parameter, my_control )
- long parameter ;
- ControlHandle my_control ;
- {
- BitMap arrows ;
- Rect box ;
- Rect box2 ;
- int i ;
-
- /* Save old clip region */
- if( OLD_CLIP != NULL && NEW_CLIP != NULL ) {
- GetClip( OLD_CLIP ) ;
- RectRgn( NEW_CLIP, &CONTROL_RECT ) ;
- SectRgn( OLD_CLIP, NEW_CLIP, NEW_CLIP ) ;
- SetClip( NEW_CLIP ) ;
-
- /* Set update and hilite array */
- if( parameter >= 0 && parameter < NUM_PARTS ) {
- CONTROL_ITEM_UPDATE[parameter] = TRUE ;
- }
- if( CONTROL_HILITE > 0 && CONTROL_HILITE < UP_ARROW ) {
- CONTROL_ITEM_HILITE[CONTROL_HILITE] = TRUE ;
- CONTROL_HILITED = CONTROL_HILITE ;
- CONTROL_LST_HILITED = CONTROL_HILITED ;
- CONTROL_ITEM_UPDATE[UP_ARROW] = TRUE ;
- }else if( CONTROL_HILITE == 0 ) {
- CONTROL_HILITED = 0 ;
- CONTROL_ITEM_UPDATE[UP_ARROW] = TRUE ;
- }else if( CONTROL_HILITE == UP_ARROW || CONTROL_HILITE == DOWN_ARROW ) {
- CONTROL_HILITED = CONTROL_LST_HILITED ;
- CONTROL_ITEM_HILITE[CONTROL_LST_HILITED] = TRUE ;
- CONTROL_ITEM_UPDATE[CONTROL_LST_HILITED] = TRUE ;
- CONTROL_ITEM_UPDATE[UP_ARROW] = TRUE ;
- }
- for( i=0;i<NUM_PARTS;i++ ) {
- if( parameter == 0 ) CONTROL_ITEM_UPDATE[i] = TRUE ;
- if( parameter == i ) CONTROL_ITEM_UPDATE[i] = TRUE ;
- if( ( CONTROL_ITEM_HILITE[i] ) && ( i != CONTROL_HILITED ) &&
- ( CONTROL_HILITED < UP_ARROW ) ) {
- CONTROL_ITEM_HILITE[i] = FALSE ;
- CONTROL_ITEM_UPDATE[i] = TRUE ;
- }
- }
-
- /* Now do drawing */
- for( i=0;i<NUM_PARTS;i++ ) {
- if( CONTROL_ITEM_UPDATE[i] ) {
- CONTROL_ITEM_UPDATE[i] = FALSE ;
- switch( i ) {
- case 0:
- /* Frame the control */
- box = CONTROL_RECT ;
- if( parameter == 0 ) {
- EraseRect( &box ) ;
- }
- box.bottom -= 2 ;
- box.right -= 2 ;
- FrameRect( &box ) ;
- /* Now draw the shadow */
- MoveTo( box.left+1, box.bottom ) ;
- LineTo( box.right, box.bottom ) ;
- LineTo( box.right, box.top+1 ) ;
- /* Also draw the slashes and colon here */
- MoveTo( CONTROL_CHAR_POS[2].h, CONTROL_CHAR_POS[2].v ) ;
- DrawChar( CONTROL_CHAR_ARY[2] ) ;
- MoveTo( CONTROL_CHAR_POS[5].h, CONTROL_CHAR_POS[5].v ) ;
- DrawChar( CONTROL_CHAR_ARY[5] ) ;
- MoveTo( CONTROL_CHAR_POS[10].h, CONTROL_CHAR_POS[10].v ) ;
- DrawChar( CONTROL_CHAR_ARY[10] ) ;
- break ;
- case MONTH_PART_CODE:
- /* Draw month characters */
- EraseRect( &CONTROL_ITEM_RECT[MONTH_PART_CODE] ) ;
- MoveTo( CONTROL_CHAR_POS[0].h, CONTROL_CHAR_POS[0].v ) ;
- DrawChar( CONTROL_CHAR_ARY[0] ) ;
- MoveTo( CONTROL_CHAR_POS[1].h, CONTROL_CHAR_POS[1].v ) ;
- DrawChar( CONTROL_CHAR_ARY[1] ) ;
- if( CONTROL_ITEM_HILITE[MONTH_PART_CODE] ) {
- InvertRect( &CONTROL_ITEM_RECT[MONTH_PART_CODE] ) ;
- }
- break ;
- case DAY_PART_CODE:
- /* Draw day characters */
- EraseRect( &CONTROL_ITEM_RECT[DAY_PART_CODE] ) ;
- MoveTo( CONTROL_CHAR_POS[3].h, CONTROL_CHAR_POS[3].v ) ;
- DrawChar( CONTROL_CHAR_ARY[3] ) ;
- MoveTo( CONTROL_CHAR_POS[4].h, CONTROL_CHAR_POS[4].v ) ;
- DrawChar( CONTROL_CHAR_ARY[4] ) ;
- if( CONTROL_ITEM_HILITE[DAY_PART_CODE] ) {
- InvertRect( &CONTROL_ITEM_RECT[DAY_PART_CODE] ) ;
- }
- break ;
- case YEAR_PART_CODE:
- /* Draw year characters */
- EraseRect( &CONTROL_ITEM_RECT[YEAR_PART_CODE] ) ;
- MoveTo( CONTROL_CHAR_POS[6].h, CONTROL_CHAR_POS[6].v ) ;
- DrawChar( CONTROL_CHAR_ARY[6] ) ;
- MoveTo( CONTROL_CHAR_POS[7].h, CONTROL_CHAR_POS[7].v ) ;
- DrawChar( CONTROL_CHAR_ARY[7] ) ;
- if( CONTROL_ITEM_HILITE[YEAR_PART_CODE] ) {
- InvertRect( &CONTROL_ITEM_RECT[YEAR_PART_CODE] ) ;
- }
- break ;
- case HOUR_PART_CODE:
- /* Draw hour characters */
- EraseRect( &CONTROL_ITEM_RECT[HOUR_PART_CODE] ) ;
- MoveTo( CONTROL_CHAR_POS[8].h, CONTROL_CHAR_POS[8].v ) ;
- DrawChar( CONTROL_CHAR_ARY[8] ) ;
- MoveTo( CONTROL_CHAR_POS[9].h, CONTROL_CHAR_POS[9].v ) ;
- DrawChar( CONTROL_CHAR_ARY[9] ) ;
- if( CONTROL_ITEM_HILITE[HOUR_PART_CODE] ) {
- InvertRect( &CONTROL_ITEM_RECT[HOUR_PART_CODE] ) ;
- }
- break ;
- case MINUTE_PART_CODE:
- /* Draw minute characters */
- EraseRect( &CONTROL_ITEM_RECT[MINUTE_PART_CODE] ) ;
- MoveTo( CONTROL_CHAR_POS[11].h, CONTROL_CHAR_POS[11].v ) ;
- DrawChar( CONTROL_CHAR_ARY[11] ) ;
- MoveTo( CONTROL_CHAR_POS[12].h, CONTROL_CHAR_POS[12].v ) ;
- DrawChar( CONTROL_CHAR_ARY[12] ) ;
- if( CONTROL_ITEM_HILITE[MINUTE_PART_CODE] ) {
- InvertRect( &CONTROL_ITEM_RECT[MINUTE_PART_CODE] ) ;
- }
- break ;
- case UP_ARROW:
- case DOWN_ARROW:
- /* draw the arrows */
- SetRect( &box, CONTROL_ITEM_RECT[UP_ARROW].left,
- CONTROL_ITEM_RECT[UP_ARROW].top,
- CONTROL_ITEM_RECT[DOWN_ARROW].right,
- CONTROL_ITEM_RECT[DOWN_ARROW].bottom ) ;
- /* If there are no items hilited then erase arrows */
- if( CONTROL_HILITED == 0 ) {
- EraseRect( &box ) ;
- }else{
- SetRect( &box2, 0,0,11,18 ) ;
- arrows.rowBytes = 2 ;
- arrows.bounds = box2 ;
- arrows.baseAddr = bits ;
- CopyBits( &arrows, &CONTROL_WINDOW->portBits, &box2, &box,
- srcOr, NULL ) ;
- }
- break ;
- }
- }
- }
-
- /* Restore old clip region */
- SetClip( OLD_CLIP ) ;
- }
- return ;
- }
- long doTestControl( pt, my_control )
- long pt ;
- ControlHandle my_control ;
- {
- int i ;
- long result = 0 ;
-
- for( i=1;i<NUM_PARTS;i++ ) {
- if( PtInRect( pt, &CONTROL_ITEM_RECT[i] ) ) {
- result = i ;
- break ;
- }
- }
- return result ;
- }
- void doCalcCRgns( region, my_control )
- RgnHandle region ;
- ControlHandle my_control ;
- {
- RectRgn( (RgnHandle)region, &CONTROL_RECT ) ;
- return ;
- }
- void doTrackControl( hilite, my_control )
- int hilite ;
- ControlHandle my_control ;
- {
- /* Is it in the arrows */
- if( hilite == UP_ARROW || hilite == DOWN_ARROW ) {
- /* Delay to keep from changing the numbers too fast */
- if( DE_BOUNCER ) {
- DE_BOUNCER-- ;
- return ;
- }
- if( hilite == UP_ARROW ) {
- switch( CONTROL_HILITED ) {
- case MONTH_PART_CODE:
- if( CONTROL_DATE_TIME.month >= 12 ) {
- CONTROL_DATE_TIME.month = 1 ;
- }else CONTROL_DATE_TIME.month++ ;
- CONTROL_ITEM_UPDATE[MONTH_PART_CODE] = TRUE ;
- break ;
- case DAY_PART_CODE:
- if( CONTROL_DATE_TIME.day >= NUM_DAYS[CONTROL_DATE_TIME.month-1] ) {
- CONTROL_DATE_TIME.day = 1 ;
- }else CONTROL_DATE_TIME.day++ ;
- CONTROL_ITEM_UPDATE[DAY_PART_CODE] = TRUE ;
- break ;
- case YEAR_PART_CODE:
- if( CONTROL_DATE_TIME.year >= 1999 ) {
- CONTROL_DATE_TIME.year = 1904 ;
- }else CONTROL_DATE_TIME.year++ ;
- CONTROL_ITEM_UPDATE[YEAR_PART_CODE] = TRUE ;
- if( ( CONTROL_DATE_TIME.year % 4 ) == 0 ) {
- NUM_DAYS[1] = 29 ;
- }else{
- NUM_DAYS[1] = 28 ;
- }
- break ;
- case HOUR_PART_CODE:
- if( CONTROL_DATE_TIME.hour >= 23 ) {
- CONTROL_DATE_TIME.hour = 0 ;
- }else CONTROL_DATE_TIME.hour++ ;
- CONTROL_ITEM_UPDATE[HOUR_PART_CODE] = TRUE ;
- break ;
- case MINUTE_PART_CODE:
- if( CONTROL_DATE_TIME.minute >= 59 ) {
- CONTROL_DATE_TIME.minute = 0 ;
- }else CONTROL_DATE_TIME.minute++ ;
- CONTROL_ITEM_UPDATE[MINUTE_PART_CODE] = TRUE ;
- break ;
- }
- }else if( hilite == DOWN_ARROW ) {
- switch( CONTROL_HILITED ) {
- case MONTH_PART_CODE:
- if( CONTROL_DATE_TIME.month <= 1 ) {
- CONTROL_DATE_TIME.month = 12 ;
- }else CONTROL_DATE_TIME.month-- ;
- CONTROL_ITEM_UPDATE[MONTH_PART_CODE] = TRUE ;
- break ;
- case DAY_PART_CODE:
- if( CONTROL_DATE_TIME.day <= 1 ) {
- CONTROL_DATE_TIME.day = NUM_DAYS[CONTROL_DATE_TIME.month-1] ;
- }else CONTROL_DATE_TIME.day-- ;
- CONTROL_ITEM_UPDATE[DAY_PART_CODE] = TRUE ;
- break ;
- case YEAR_PART_CODE:
- if( CONTROL_DATE_TIME.year <= 1904 ) {
- CONTROL_DATE_TIME.year = 1999 ;
- }else CONTROL_DATE_TIME.year-- ;
- CONTROL_ITEM_UPDATE[YEAR_PART_CODE] = TRUE ;
- if( ( CONTROL_DATE_TIME.year % 4 ) == 0 ) {
- NUM_DAYS[1] = 29 ;
- }else{
- NUM_DAYS[1] = 28 ;
- }
- break ;
- case HOUR_PART_CODE:
- if( CONTROL_DATE_TIME.hour <= 0 ) {
- CONTROL_DATE_TIME.hour = 23 ;
- }else CONTROL_DATE_TIME.hour-- ;
- CONTROL_ITEM_UPDATE[HOUR_PART_CODE] = TRUE ;
- break ;
- case MINUTE_PART_CODE:
- if( CONTROL_DATE_TIME.minute <= 0 ) {
- CONTROL_DATE_TIME.minute = 59 ;
- }else CONTROL_DATE_TIME.minute-- ;
- CONTROL_ITEM_UPDATE[MINUTE_PART_CODE] = TRUE ;
- break ;
- }
- }
- /* Reset delay */
- DE_BOUNCER = DELAY ;
- NEW_DATE_TIME = CONTROL_DATE_TIME ;
- Date2Chars( &CONTROL_DATE_TIME, CONTROL_CHAR_ARY ) ;
- doDrawControl( hilite, my_control ) ;
- }else if( hilite >= 0 && hilite < UP_ARROW ) {
- HiliteControl( my_control, hilite ) ;
- }
- return ;
- }